package com.spring.http;

import java.io.IOException;
import java.util.Map;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;

public final class HttpContext {
	private Map<String, Object> params = null;
	/**
	 * 参数注入
	 * @return
	 */
	public Map<String, Object> preParams() {
		return params;
	}

	public final static int JSON_DATA = 2;
	public final static int FORM_DATA = 1;

	public final static int HTTP_GET = 0;
	public final static int HTTP_POST = 1;

	private int method; //
	private int dataType; //
	private String uri;// HTTP URL 路径
	private FullHttpRequest req;// HTTP 请求
	private FullHttpResponse res;// HTTP 响应
	private ChannelHandlerContext ctx;// 信道
	private String text;// websocket text
	private long uid = 0L;

	public Map<String, Object> getParams() throws Exception {
		if (params != null)
			return params;
		return HttpUtils.getHttpParams(req);
	}

	public String getParam() throws IOException {
		return "";
		// return HttpUtils.getJsonParam(req);
	}

	public int getMethod() {
		return method;
	}

	public void setMethod(int method) {
		this.method = method;
	}

	public int getDataType() {
		return dataType;
	}

	public void setDataType(int dataType) {
		this.dataType = dataType;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	public ChannelHandlerContext getCtx() {
		return ctx;
	}

	public void setCtx(ChannelHandlerContext ctx) {
		this.ctx = ctx;
	}

	public FullHttpRequest getReq() {
		return req;
	}

	public void setReq(FullHttpRequest req) {
		this.req = req;
	}

	public FullHttpResponse getRes() {
		return res;
	}

	public void setRes(FullHttpResponse res) {
		this.res = res;
	}

	public long getUid() {
		return uid;
	}

	public void setUid(long uid) {
		this.uid = uid;
	}
	

}
